<template>
  <el-dialog v-model="dialogVisible" title="修改密码" width="30%">
    <el-form :model="form" label-width="80px">
      <el-form-item label="qq邮箱">
        <el-input
          v-model="form.userEmail"
          placeholder="请输入qq邮箱"
          style="width: 215px; margin-right: 20px"
        />
        <el-button type="primary" @click="handleSendCode">发送验证码</el-button>
      </el-form-item>
      <el-form-item label="新的密码">
        <el-input v-model="form.password" placeholder="请输入新的密码" />
      </el-form-item>
      <el-form-item label="验证码">
        <el-input v-model="form.code" placeholder="请输入验证码" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <div
          style="
            width: 100%;
            text-align: center;
            height: 50px;
            margin-top: -20px;
          "
        >
          <el-button
            @click="handleEdited"
            type="primary"
            style="width: 100px; height: 40px"
            >确定</el-button
          >
        </div>
      </span>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { ref, reactive } from "vue";
import { getSystemEmailCode, updateUserPassword } from "@/api/user";
import { ElMessage } from "element-plus";
const form = reactive({
  userEmail: "",
  password: "",
  code: "",
});
const handleSendCode = async () => {
  await getSystemEmailCode(form.userEmail).then((res: any) => {
    ElMessage({
      message: res.message,
      type: "success",
    });
  });
};
const handleEdited = async () => {
  await updateUserPassword(form).then((res: any) => {
    dialogVisible.value = false;
    ElMessage({
      message: res.message,
      type: "success",
    });
  });
};
const showDialog = () => {
  dialogVisible.value = true;
};
defineExpose({
  showDialog,
});
const dialogVisible = ref(false);
</script>
<style scoped></style>
